package znbkTopicType.response;

import android.content.Context;
import android.os.Handler;
import android.text.Html;
import android.text.Spanned;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.lancooznbk.R;

import org.apache.commons.lang3.StringEscapeUtils;

import lancooControl.Control;
import lancooControl.CustomAnswerChoiceView;
import znbkTestPaperCtfd.ZnbkPaperCtfdInfor;
import znbkTestPaperCtfd.activity.WrongTopicTutoringPaperActivity;
import znbkTestPaperInfor.ZnbkPaperDef;
import znbkTestPaperNtxl.activity.TrainingDifficultProblemsPaperActivity;
import znbkTestPaperRdqh.activity.WeekAscensionPaperActivity;
import znbkTestPaperXtfx.activity.SystemReviewPaperActivity;

import static znbkTestPaperCtfd.activity.WrongTopicTutoringPaperActivity.mEntityCtfd;
import static znbkTestPaperLstjt.activity.HistoryRecommendQuesPaperActivity.mEntityLstjt;
import static znbkTestPaperNtxl.activity.TrainingDifficultProblemsPaperActivity.mEntityNtxl;
import static znbkTestPaperRdqh.activity.WeekAscensionPaperActivity.mEntityRdqh;
import static znbkTestPaperXtfx.activity.SystemReviewPaperActivity.mEntityXtfx;

/**
 * Created by Administrator on 2018\2\23 0023.
 */

public class ZnbkResponseXztAdapter extends BaseAdapter {

    private LayoutInflater mInflater;
    //当前试题数量
    private int SumItem;
    //当前试题在当前试题的ID
    private int PaperID;
    //当前小题ID
    private int OptionID;
    private Context mContext;

    private int ModelFrom;


    private int tvBlack;
    private int tvBlue;
    private int tvWhite;
    private int tvGreen;
    private int tvRed;
    private int btnWhite;
    private int btnBlue;
    private int btnGreen;
    private int btnRed;

    /*
    * 获取小题选项信息
    * */
    private int status;//试卷的作答状态
    private int sumOption;//选项的个数
    private String stuAnswer;//用户答案
    private String answer;//正确答案
    private int itemIndex;//小题数字编号
    private String itemContent;//小题题目信息
    private String analysis;//答案解析
    private int totalItemCount;//小题数量

    private String[] optionIndex;//选项号所对应的文字
    private String[] option;//选项内容对应的文字



    private ViewHolder holder = null;
    private class ViewHolder{
        TextView TvItemContent;//大题文本题干
        LinearLayout LayoutOptions;//选项显示区
        LinearLayout LayoutCheckAnalysis;//答案显示区
        LinearLayout LayoutStuAnswer;
        LinearLayout LayoutAnswer;
        LinearLayout LayoutAnalysis;
        TextView TvAnswer;//正确答案
        TextView TvStuAnswer;//学生答案
        TextView TvAnalysis;//解析
        TextView TvAnswerAmount;//小题总数

        private ViewHolder(View convertView) {
            TvItemContent = (TextView) convertView.findViewById(R.id.tv_itemContent);
            LayoutOptions = (LinearLayout) convertView.findViewById(R.id.layout_options);
            LayoutCheckAnalysis = (LinearLayout) convertView.findViewById(R.id.layout_checkAnalysis);
            LayoutStuAnswer = (LinearLayout) convertView.findViewById(R.id.layout_stuAnswer);
            LayoutAnswer = (LinearLayout) convertView.findViewById(R.id.layout_answer);
            LayoutAnalysis = (LinearLayout) convertView.findViewById(R.id.layout_analysis);
            TvAnswer = (TextView) convertView.findViewById(R.id.tv_answer);
            TvStuAnswer = (TextView) convertView.findViewById(R.id.tv_stuAnswer);
            TvAnalysis = (TextView) convertView.findViewById(R.id.tv_analysis);
            TvAnswerAmount = (TextView) convertView.findViewById(R.id.tv_answerAmount);

        }
    }

    private CustomAnswerChoiceView[] ChoiceAnswer;//选项信息


    public ZnbkResponseXztAdapter(Context context, int sumItem, int paperID,int optionID, int modelFrom) {
        mInflater = LayoutInflater.from(context);
        this.mContext = context;
        this.SumItem = sumItem;
        this.PaperID = paperID;
        this.OptionID = optionID;
        this.ModelFrom = modelFrom;

        tvBlack = mContext.getResources().getColor(R.color.black);
        tvBlue = mContext.getResources().getColor(R.color.blue);
        tvWhite = mContext.getResources().getColor(R.color.white);
        tvGreen = mContext.getResources().getColor(R.color.green);
        tvRed = mContext.getResources().getColor(R.color.red);

        btnWhite = R.mipmap.option_normal;
        btnBlue = R.mipmap.option_select;
        btnGreen = R.mipmap.option_right;
        btnRed = R.mipmap.option_wrong;

    }

    @Override
    public int getCount() {
        return SumItem;
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.znbk_adapter_response_xzt_item, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        /*
        * 获取试题相关信息
        * */
        getQuesInfor();

        /*
        * 展示作答区内容及实现作答流程
        * */
        showQuesInfor();

        /*
        * 已提交状态下，初始化答案解析
        * */
        showAnalysis();

        return convertView;
    }

    /*
    * 获取试题相关信息
    * */
    private void getQuesInfor(){

        if(ModelFrom==ZnbkPaperDef.FROM_TRAINING_DIFFICULT_PROBLEMS) {

            //试卷的作答状态
            status = mEntityNtxl.getAnswerState();
            //小题编号
            itemIndex = mEntityNtxl.getTKQue().getChildList().get(OptionID).getChildIndex();
            //获取大题题干内容
            itemContent = mEntityNtxl.getTKQue().getChildList().get(OptionID).getChildAsk();
            //选项个数
            sumOption = mEntityNtxl.getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildOptionList().size();
            //用户答案
            stuAnswer = mEntityNtxl.getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildStuAnswer();
            //正确答案
            answer = mEntityNtxl.getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildAnswer();
            //答案解析
            analysis =  mEntityNtxl.getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildAnalyze();
            //小题数量
            totalItemCount = mEntityNtxl.getTKQue().getTotalItemCount();
            //获取选项题号及选项内容
            optionIndex = new String[sumOption];
            option = new String[sumOption];
            for (int i = 0; i < sumOption; i++) {
                optionIndex[i] = mEntityNtxl.getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildOptionList().get(i).getOptionIndex();
                option[i] = mEntityNtxl.getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildOptionList().get(i).getOptionContent();
            }
        }else if(ModelFrom == ZnbkPaperDef.FROM_SYSTEM_REVIEW){
            //试卷的作答状态
            status = mEntityXtfx.getModelSinglePaperInfo().getModelPaperInfo().getAnswerState();
            //小题编号
            itemIndex = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(OptionID).getChildIndex();
            //获取大题题干内容
            itemContent = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(OptionID).getChildAsk();
            //选项个数
            sumOption = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(OptionID).getSubChildList().get(0).getSubChildOptionList().size();
            //用户答案
            stuAnswer = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(OptionID).getSubChildList().get(0).getSubChildStuAnswer();
            //正确答案
            answer = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(OptionID).getSubChildList().get(0).getSubChildAnswer();
            //答案解析
            analysis =  mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(OptionID).getSubChildList().get(0).getSubChildAnalyze();
            //小题数量
            totalItemCount = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getTotalItemCount();
            //获取选项题号及选项内容
            optionIndex = new String[sumOption];
            option = new String[sumOption];
            for (int i = 0; i < sumOption; i++) {
                optionIndex[i] = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(OptionID).getSubChildList().get(0).getSubChildOptionList().get(i).getOptionIndex();
                option[i] = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(OptionID).getSubChildList().get(0).getSubChildOptionList().get(i).getOptionContent();
            }
        }else if(ModelFrom == ZnbkPaperDef.FROM_WEEK_ASCENSION){
            //试卷的作答状态
            status = mEntityRdqh.getModelSinglePaperInfo().getModelPaperInfo().getAnswerState();
            //小题编号
            itemIndex = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(OptionID).getChildIndex();
            //获取大题题干内容
            itemContent = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(OptionID).getChildAsk();
            //选项个数
            sumOption = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(OptionID).getSubChildList().get(0).getSubChildOptionList().size();
            //用户答案
            stuAnswer = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(OptionID).getSubChildList().get(0).getSubChildStuAnswer();
            //正确答案
            answer = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(OptionID).getSubChildList().get(0).getSubChildAnswer();
            //答案解析
            analysis =  mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(OptionID).getSubChildList().get(0).getSubChildAnalyze();
            //小题数量
            totalItemCount = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getTotalItemCount();
            //获取选项题号及选项内容
            optionIndex = new String[sumOption];
            option = new String[sumOption];
            for (int i = 0; i < sumOption; i++) {
                optionIndex[i] = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(OptionID).getSubChildList().get(0).getSubChildOptionList().get(i).getOptionIndex();
                option[i] = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(OptionID).getSubChildList().get(0).getSubChildOptionList().get(i).getOptionContent();
            }
        }else if(ModelFrom == ZnbkPaperDef.FROM_WRONG_TOPIC_TUTORING){

            int anotherPaperID = -1;
            if(PaperID==0) {
                //试卷的作答状态
                status = 3;
                //小题数量
                totalItemCount = mEntityCtfd.getPrimitiveQues().getTKQue().getTotalItemCount();
                //小题编号
                itemIndex = mEntityCtfd.getPrimitiveQues().getTKQue().getChildList().get(OptionID).getChildIndex();
                //获取小题题干内容
                itemContent = mEntityCtfd.getPrimitiveQues().getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildAsk();
                //选项个数
                sumOption = mEntityCtfd.getPrimitiveQues().getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildOptionList().size();
                //用户答案
                stuAnswer = mEntityCtfd.getPrimitiveQues().getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildStuAnswer();
                //正确答案
                answer = mEntityCtfd.getPrimitiveQues().getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildAnswer();
                //答案解析
                analysis = mEntityCtfd.getPrimitiveQues().getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildAnalyze();
                //获取选项题号及选项内容
                optionIndex = new String[sumOption];
                option = new String[sumOption];
                for (int i = 0; i < sumOption; i++) {
                    optionIndex[i] = mEntityCtfd.getPrimitiveQues().getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildOptionList().get(i).getOptionIndex();
                    option[i] = mEntityCtfd.getPrimitiveQues().getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildOptionList().get(i).getOptionContent();
                }
            }else{

                if(PaperID==1){
                    //试卷的作答状态
                    status = 3;
                    anotherPaperID = PaperID-1;
                    if (mEntityCtfd.getClassicalQues()!= null) {
                        //小题数量
                        totalItemCount = mEntityCtfd.getClassicalQues().getTKQue().getTotalItemCount();
                        //小题编号
                        itemIndex = mEntityCtfd.getClassicalQues().getTKQue().getChildList().get(OptionID).getChildIndex();
                        //获取小题题干内容
                        itemContent = mEntityCtfd.getClassicalQues().getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildAsk();
                        //选项个数
                        sumOption = mEntityCtfd.getClassicalQues().getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildOptionList().size();
                        //用户答案
                        stuAnswer = mEntityCtfd.getClassicalQues().getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildStuAnswer();
                        //正确答案
                        answer = mEntityCtfd.getClassicalQues().getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildAnswer();
                        //答案解析
                        analysis = mEntityCtfd.getClassicalQues().getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildAnalyze();
                        //获取选项题号及选项内容
                        optionIndex = new String[sumOption];
                        option = new String[sumOption];
                        for (int i = 0; i < sumOption; i++) {
                            optionIndex[i] = mEntityCtfd.getClassicalQues().getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildOptionList().get(i).getOptionIndex();
                            option[i] = mEntityCtfd.getClassicalQues().getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildOptionList().get(i).getOptionContent();
                        }
                    }else{
                        //试卷的作答状态
                        status = mEntityCtfd.getRecQues().get(0).getAnswerState();
                        //小题数量
                        totalItemCount = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getTotalItemCount();
                        //小题编号
                        itemIndex = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(OptionID).getChildIndex();
                        //获取小题题干内容
                        itemContent = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildAsk();
                        //选项个数
                        sumOption = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildOptionList().size();
                        //用户答案
                        stuAnswer = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildStuAnswer();
                        //正确答案
                        answer = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildAnswer();
                        //答案解析
                        analysis = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildAnalyze();
                        //获取选项题号及选项内容
                        optionIndex = new String[sumOption];
                        option = new String[sumOption];
                        for (int i = 0; i < sumOption; i++) {
                            optionIndex[i] = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildOptionList().get(i).getOptionIndex();
                            option[i] = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildOptionList().get(i).getOptionContent();
                        }
                    }
                }else{

                    if (mEntityCtfd.getClassicalQues()!= null) {
                        anotherPaperID = PaperID - 2;
                    } else {
                        anotherPaperID = PaperID - 1;
                    }
                    //试卷的作答状态
                    status = status = mEntityCtfd.getRecQues().get(0).getAnswerState();
                    //小题数量
                    totalItemCount = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getTotalItemCount();
                    //小题编号
                    itemIndex = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(OptionID).getChildIndex();
                    //获取小题题干内容
                    itemContent = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildAsk();
                    //选项个数
                    sumOption = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildOptionList().size();
                    //用户答案
                    stuAnswer = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildStuAnswer();
                    //正确答案
                    answer = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildAnswer();
                    //答案解析
                    analysis = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildAnalyze();
                    //获取选项题号及选项内容
                    optionIndex = new String[sumOption];
                    option = new String[sumOption];
                    for (int i = 0; i < sumOption; i++) {
                        optionIndex[i] = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildOptionList().get(i).getOptionIndex();
                        option[i] = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildOptionList().get(i).getOptionContent();
                    }
                }
            }
        }else if(ModelFrom==ZnbkPaperDef.FROM_HISTORY_RECOMMEND_QUESTION){
            //试卷的作答状态
            status = 3;
            //小题编号
            itemIndex = mEntityLstjt.get(PaperID).getTKQue().getChildList().get(OptionID).getChildIndex();
            //获取大题题干内容
            itemContent = mEntityLstjt.get(PaperID).getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildAsk();
            //选项个数
            sumOption = mEntityLstjt.get(PaperID).getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildOptionList().size();
            //用户答案
            stuAnswer = mEntityLstjt.get(PaperID).getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildStuAnswer();
            //正确答案
            answer = mEntityLstjt.get(PaperID).getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildAnswer();
            //答案解析
            analysis =  mEntityLstjt.get(PaperID).getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildAnalyze();
            //小题数量
            totalItemCount = mEntityLstjt.get(PaperID).getTKQue().getTotalItemCount();
            //获取选项题号及选项内容
            optionIndex = new String[sumOption];
            option = new String[sumOption];
            for (int i = 0; i < sumOption; i++) {
                optionIndex[i] = mEntityLstjt.get(PaperID).getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildOptionList().get(i).getOptionIndex();
                option[i] = mEntityLstjt.get(PaperID).getTKQue().getChildList().get(OptionID).getSubChildList().get(0).getSubChildOptionList().get(i).getOptionContent();
            }
        }

    }

    /*
    * 展示试题信息
    * */
    Handler htmlHandlerItemContent = new Handler();
    private void showQuesInfor(){

        holder.TvAnswerAmount.setText("本题包含"+totalItemCount+"个小题");

        /*
        * 显示题目题干
        * */
        itemContent = StringEscapeUtils.unescapeXml("("+itemIndex+")"+itemContent);

        new Thread(new Runnable()
        {
            @Override
            public void run()
            {
                final Spanned tvItemContent = Html.fromHtml(itemContent, Control.imgGetter,null);
                htmlHandlerItemContent.post(new Runnable()
                {
                    @Override
                    public void run()
                    {
                        holder.TvItemContent.setText(tvItemContent);
                        holder.TvItemContent.setTextSize(18);
                    }
                });
            }
        }).start();

        /*
        * 显示选项内容
        * */
        ChoiceAnswer = new CustomAnswerChoiceView[sumOption];
        for(int i =0;i<sumOption;i++){
            ChoiceAnswer[i] = new CustomAnswerChoiceView(mContext);
            ChoiceAnswer[i].setAnswerChoice(optionIndex[i],tvBlack,btnWhite,option[i],tvBlack);

            final int finalI = i;
            ChoiceAnswer[i].setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Log.e("===state===", "======state===000===" + status);
                    if (status==2||status==3) {
                        return;
                    }else {

                        int RecPaperID = -1;
                        if(ModelFrom==ZnbkPaperDef.FROM_SYSTEM_REVIEW){
                            mEntityXtfx.getModelSinglePaperInfo().getModelPaperInfo().setAnswerState(1);
                            SystemReviewPaperActivity.mSbtnSubmit.setTextColor(tvWhite);

                            for (int k = 0; k < sumOption; k++) {
                                if (finalI == k) {
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnBlue,option[k],tvBlue);
                                    setStuAnswerInfor(Control.asciiToString(k + 65),RecPaperID);
                                } else {
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvBlack,btnWhite,option[k],tvBlack);
                                }
                            }

                        }else if(ModelFrom==ZnbkPaperDef.FROM_WEEK_ASCENSION){
                            mEntityRdqh.getModelSinglePaperInfo().getModelPaperInfo().setAnswerState(1);
                            WeekAscensionPaperActivity.mSbtnSubmit.setTextColor(tvWhite);

                            for (int k = 0; k < sumOption; k++) {
                                if (finalI == k) {
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnBlue,option[k],tvBlue);
                                    setStuAnswerInfor(Control.asciiToString(k + 65),RecPaperID);
                                } else {
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvBlack,btnWhite,option[k],tvBlack);
                                }
                            }
                        }else if(ModelFrom== ZnbkPaperDef.FROM_TRAINING_DIFFICULT_PROBLEMS){
                                mEntityNtxl.setAnswerState(1);
                                TrainingDifficultProblemsPaperActivity.mSbtnSubmit.setTextColor(tvWhite);

                                for (int k = 0; k < sumOption; k++) {
                                    if (finalI == k) {
                                        ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnBlue,option[k],tvBlue);
                                        setStuAnswerInfor(Control.asciiToString(k + 65),RecPaperID);
                                    } else {
                                        ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvBlack,btnWhite,option[k],tvBlack);
                                    }
                                }

                        }else if(ModelFrom==ZnbkPaperDef.FROM_WRONG_TOPIC_TUTORING) {
                            int anotherPaperID = -1;
                            if(PaperID==0){
                                return;
                            }else if(PaperID==1){
                                anotherPaperID=PaperID-1;
                                if(mEntityCtfd.getClassicalQues()!=null){
                                    return;
                                }else{
                                    if(status==2||status==3){
                                        return;
                                    }else{
                                        mEntityCtfd.getRecQues().get(0).setAnswerState(1);
                                        WrongTopicTutoringPaperActivity.mSbtnSubmit.setTextColor(tvWhite);
                                        mEntityCtfd.setStepFlag(2);
                                    }
                                }
                            }else {
                                if(mEntityCtfd.getClassicalQues()!=null){
                                    anotherPaperID = PaperID-2;
                                }else{
                                    anotherPaperID = PaperID-1;
                                }
                                if(status==2||status==3){
                                    return;
                                }else{
                                    mEntityCtfd.getRecQues().get(0).setAnswerState(1);
                                    WrongTopicTutoringPaperActivity.mSbtnSubmit.setTextColor(tvWhite);
                                    mEntityCtfd.setStepFlag(2);
                                }
                            }

                            for (int k = 0; k < sumOption; k++) {
                                if (finalI == k) {
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnBlue,option[k],tvBlue);
                                    if(mEntityCtfd.getClassicalQues()==null) {
                                        RecPaperID = PaperID - 1;
                                    }else{
                                        RecPaperID = PaperID - 2;
                                    }
                                    setStuAnswerInfor(Control.asciiToString(k + 65),RecPaperID);
                                } else {
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvBlack,btnWhite,option[k],tvBlack);
                                }
                            }

                        }else if(ModelFrom== ZnbkPaperDef.FROM_HISTORY_RECOMMEND_QUESTION){
                            return;
                        }
                    }
                }
            });

            ChoiceAnswer[i].BtnChoice.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Log.e("===state===", "======state===111===" + status);
                    if (status==2||status==3) {
                        return;
                    }else {
                        int RecPaperID = -1;
                        if(ModelFrom==ZnbkPaperDef.FROM_SYSTEM_REVIEW){
                            mEntityXtfx.getModelSinglePaperInfo().getModelPaperInfo().setAnswerState(1);
                            SystemReviewPaperActivity.mSbtnSubmit.setTextColor(tvWhite);

                            for (int k = 0; k < sumOption; k++) {
                                if (finalI == k) {
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnBlue,option[k],tvBlue);
                                    setStuAnswerInfor(Control.asciiToString(k + 65),RecPaperID);
                                } else {
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvBlack,btnWhite,option[k],tvBlack);
                                }
                            }

                        }else if(ModelFrom==ZnbkPaperDef.FROM_WEEK_ASCENSION){
                            mEntityRdqh.getModelSinglePaperInfo().getModelPaperInfo().setAnswerState(1);
                            WeekAscensionPaperActivity.mSbtnSubmit.setTextColor(tvWhite);

                            for (int k = 0; k < sumOption; k++) {
                                if (finalI == k) {
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnBlue,option[k],tvBlue);
                                    setStuAnswerInfor(Control.asciiToString(k + 65),RecPaperID);
                                } else {
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvBlack,btnWhite,option[k],tvBlack);
                                }
                            }
                        }else if(ModelFrom== ZnbkPaperDef.FROM_TRAINING_DIFFICULT_PROBLEMS){
                            mEntityNtxl.setAnswerState(1);
                            TrainingDifficultProblemsPaperActivity.mSbtnSubmit.setTextColor(tvWhite);

                            for (int k = 0; k < sumOption; k++) {
                                if (finalI == k) {
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnBlue,option[k],tvBlue);
                                    setStuAnswerInfor(Control.asciiToString(k + 65),RecPaperID);
                                } else {
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvBlack,btnWhite,option[k],tvBlack);
                                }
                            }

                        }else if(ModelFrom==ZnbkPaperDef.FROM_WRONG_TOPIC_TUTORING) {
                            int anotherPaperID = -1;
                            if(PaperID==0){
                                return;
                            }else if(PaperID==1){
                                anotherPaperID=PaperID-1;
                                if(mEntityCtfd.getClassicalQues()!=null){
                                    return;
                                }else{
                                    if(status==2||status==3){
                                        return;
                                    }else{
                                        mEntityCtfd.getRecQues().get(0).setAnswerState(1);
                                        WrongTopicTutoringPaperActivity.mSbtnSubmit.setTextColor(tvWhite);
                                        mEntityCtfd.setStepFlag(2);
                                    }
                                }
                            }else {
                                if(mEntityCtfd.getClassicalQues()!=null){
                                    anotherPaperID = PaperID-2;
                                }else{
                                    anotherPaperID = PaperID-1;
                                }
                                if(status==2||status==3){
                                    return;
                                }else{
                                    mEntityCtfd.getRecQues().get(0).setAnswerState(1);
                                    WrongTopicTutoringPaperActivity.mSbtnSubmit.setTextColor(tvWhite);
                                    mEntityCtfd.setStepFlag(2);
                                }
                            }

                            for (int k = 0; k < sumOption; k++) {
                                if (finalI == k) {
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnBlue,option[k],tvBlue);
                                    if(mEntityCtfd.getClassicalQues()==null) {
                                        RecPaperID = PaperID - 1;
                                    }else{
                                        RecPaperID = PaperID - 2;
                                    }
                                    setStuAnswerInfor(Control.asciiToString(k + 65),RecPaperID);
                                } else {
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvBlack,btnWhite,option[k],tvBlack);
                                }
                            }


                        }else if(ModelFrom== ZnbkPaperDef.FROM_HISTORY_RECOMMEND_QUESTION){
                            return;
                        }
                    }
                }
            });

            holder.LayoutOptions.addView(ChoiceAnswer[i]);

        }

        if (status==2||status==3) {
            //已提交
            int currentOption = -1;
            int currentTrueOption = -1;
            /*
            * 学生答案不为空
            * */
            if(!stuAnswer.equals("")){
                currentOption = Integer.valueOf(Control.stringToAscii(stuAnswer)) - 65;
                currentTrueOption = Integer.valueOf(Control.stringToAscii(answer)) - 65;
                if (stuAnswer.equals(answer)) {
                    for (int k = 0; k < sumOption; k++) {
                        if (currentOption == k) {
                            ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnGreen,option[k],tvGreen);
                        }
                    }
                } else if (!stuAnswer.equals(answer)) {
                    for (int k = 0; k < sumOption; k++) {

                        if (currentOption == k) {
                            ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnRed,option[k],tvRed);
                        }
                        if(currentTrueOption == k){
                            ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnGreen,option[k],tvGreen);
                        }
                    }
                }
            }
            /*
            * 学生答案为空
            * */
            else{
                currentTrueOption = Integer.valueOf(Control.stringToAscii(answer)) - 65;
                for (int k = 0; k < sumOption; k++) {

                    if(currentTrueOption == k){
                        ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnGreen,option[k],tvGreen);
                    }
                }
            }

        }else{
            //未提交

            if(ModelFrom==ZnbkPaperDef.FROM_WRONG_TOPIC_TUTORING){
                int anotherPaperID = -1;
                if(PaperID==0){
                    int currentOption = -1;
                    int currentTrueOption = -1;
                    if(!stuAnswer.equals("")){
                        currentOption = Integer.valueOf(Control.stringToAscii(stuAnswer)) - 65;
                        currentTrueOption = Integer.valueOf(Control.stringToAscii(answer)) - 65;
                        if (stuAnswer.equals(answer)) {
                            for (int k = 0; k < sumOption; k++) {
                                if (currentOption == k) {
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnGreen,option[k],tvGreen);
                                }
                            }
                        } else if (!stuAnswer.equals(answer)) {
                            for (int k = 0; k < sumOption; k++) {

                                if (currentOption == k) {
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnRed,option[k],tvRed);
                                }
                                if(currentTrueOption == k){
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnGreen,option[k],tvGreen);
                                }
                            }
                        }
                    }else{
                        currentTrueOption = Integer.valueOf(Control.stringToAscii(answer)) - 65;
                        for (int k = 0; k < sumOption; k++) {
                            if(currentTrueOption == k){
                                ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnGreen,option[k],tvGreen);
                            }
                        }
                    }

                }else if(PaperID==1){
                    anotherPaperID = PaperID-1;
                    if(mEntityCtfd.getClassicalQues()!=null){
                        int currentTrueOption = -1;
                        currentTrueOption = Integer.valueOf(Control.stringToAscii(answer)) - 65;
                        for (int k = 0; k < sumOption; k++) {
                            if(currentTrueOption == k){
                                ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnGreen,option[k],tvGreen);
                            }
                        }
                    }else{
                        if (!stuAnswer.equals("")) {

                            int trueOption = Integer.valueOf(Control.stringToAscii(stuAnswer)) - 65;
                            Log.e("==AAA=11=", "======trueOption======" + trueOption);

                            for (int k = 0; k < sumOption; k++) {
                                if (trueOption == k) {
                                    ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnBlue,option[k],tvBlue);
                                }
                            }

                        }
                    }
                }else{
                    if (!stuAnswer.equals("")) {

                        int trueOption = Integer.valueOf(Control.stringToAscii(stuAnswer)) - 65;
                        Log.e("==AAA=11=", "======trueOption======" + trueOption);

                        for (int k = 0; k < sumOption; k++) {
                            if (trueOption == k) {
                                ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnBlue,option[k],tvBlue);
                            }
                        }

                    }
                }
            }else if(ModelFrom==ZnbkPaperDef.FROM_SYSTEM_REVIEW||
                    ModelFrom==ZnbkPaperDef.FROM_WEEK_ASCENSION||
                    ModelFrom==ZnbkPaperDef.FROM_TRAINING_DIFFICULT_PROBLEMS||
                    ModelFrom==ZnbkPaperDef.FROM_HISTORY_RECOMMEND_QUESTION){

                /*非错题辅导*/
                if (!stuAnswer.equals("")) {

                    int trueOption = Integer.valueOf(Control.stringToAscii(stuAnswer)) - 65;

                    for (int k = 0; k < sumOption; k++) {
                        if (trueOption == k) {
                            ChoiceAnswer[k].setAnswerChoice(optionIndex[k],tvWhite,btnBlue,option[k],tvBlue);
                        }
                    }

                }
            }


        }

    }


    /*
    * 已提交状态试题分析部分内容展示
    * */
    private void showAnalysis() {

        Log.e("==status==", "---@@---" + status);

        /*
        * 系统复习、弱点强化、难题训练
        * */
        if(ModelFrom==ZnbkPaperDef.FROM_SYSTEM_REVIEW||
                ModelFrom==ZnbkPaperDef.FROM_WEEK_ASCENSION||
                ModelFrom==ZnbkPaperDef.FROM_TRAINING_DIFFICULT_PROBLEMS||
                ModelFrom==ZnbkPaperDef.FROM_HISTORY_RECOMMEND_QUESTION){

            if (status == 2 || status == 3) {
                /*
                * 显示回看解析
                * */
                holder.LayoutCheckAnalysis.setVisibility(View.VISIBLE);
                holder.LayoutStuAnswer.setVisibility(View.VISIBLE);

                /*
                * 显示我的答案
                * */
                if (!stuAnswer.equals("")) {
                    holder.TvStuAnswer.setText(stuAnswer);
                    if (stuAnswer.equals(answer)) {
                        holder.TvStuAnswer.setTextColor(tvGreen);
                    } else {
                        holder.TvStuAnswer.setTextColor(tvRed);
                    }
                } else {
                    holder.TvStuAnswer.setText(R.string.znbk_no_answered);
                    holder.TvStuAnswer.setTextColor(tvRed);
                }

                /*
                * 显示参考答案
                * */
                holder.TvAnswer.setText(answer);
                holder.TvAnswer.setTextColor(tvGreen);

                /*
                * 显示答案解析
                * */
                if (!analysis.equals("")) {
                    holder.TvAnalysis.setText(analysis);
                } else {
                    holder.TvAnalysis.setText(R.string.znbk_no_analysis);
                }
            } else {
                holder.LayoutCheckAnalysis.setVisibility(View.GONE);
            }
        }
        /*
        * 错题辅导
        * */
        else if (ModelFrom == ZnbkPaperDef.FROM_WRONG_TOPIC_TUTORING) {

            if (PaperID == 0) {

                //显示题目回看解析内容
                holder.LayoutCheckAnalysis.setVisibility(View.VISIBLE);
                holder.LayoutStuAnswer.setVisibility(View.VISIBLE);
                //我的答案
                if (stuAnswer.equals(answer)) {
                    holder.TvStuAnswer.setTextColor(tvGreen);
                } else {
                    holder.TvStuAnswer.setTextColor(tvRed);
                }
                if (!stuAnswer.equals("")) {
                    holder.TvStuAnswer.setText(stuAnswer);
                } else {
                    holder.TvStuAnswer.setText(R.string.znbk_no_answered);
                }
                //正确答案
                holder.TvAnswer.setText(answer);
                holder.TvAnswer.setTextColor(tvGreen);
                //答案解析
                if (!analysis.equals("")) {
                    holder.TvAnalysis.setText(analysis);
                } else {
                    holder.TvAnalysis.setText(R.string.znbk_no_analysis);
                }
                holder.TvAnalysis.setTextColor(tvBlack);

            } else if (PaperID == 1) {

                if (mEntityCtfd.getClassicalQues() != null) {
                    //显示题目回看解析内容
                    holder.LayoutCheckAnalysis.setVisibility(View.VISIBLE);
                    holder.LayoutStuAnswer.setVisibility(View.GONE);
                    //显示参考答案
                    holder.TvAnswer.setText(Html.fromHtml(answer));
                    holder.TvAnswer.setTextColor(tvGreen);
                    //显示答案解析
                    if (!analysis.equals("")) {
                        holder.TvAnalysis.setText(analysis);
                    } else {
                        holder.TvAnalysis.setText(R.string.znbk_no_analysis);
                    }

                } else {
                    if (status == 2 || status == 3) {
                        holder.LayoutCheckAnalysis.setVisibility(View.VISIBLE);
                        holder.LayoutStuAnswer.setVisibility(View.VISIBLE);
                        /*显示我的答案*/
                        if (!stuAnswer.equals("")) {
                            holder.TvStuAnswer.setText(stuAnswer);
                            if (stuAnswer.equals(answer)) {
                                holder.TvStuAnswer.setTextColor(tvGreen);
                            } else {
                                holder.TvStuAnswer.setTextColor(tvRed);
                            }
                        } else {
                            holder.TvStuAnswer.setText(R.string.znbk_no_answered);
                            holder.TvStuAnswer.setTextColor(tvRed);
                        }
                        /*显示参考答案*/
                        holder.TvAnswer.setText(answer);
                        /*显示解析*/
                        if (!analysis.equals("")) {
                            holder.TvAnalysis.setText(analysis);
                        } else {
                            holder.TvAnalysis.setText(R.string.znbk_no_analysis);
                        }
                    } else {
                        holder.LayoutCheckAnalysis.setVisibility(View.GONE);
                    }
                }
            } else {
                if (status == 2 || status == 3) {
                    holder.LayoutCheckAnalysis.setVisibility(View.VISIBLE);
                    holder.LayoutStuAnswer.setVisibility(View.VISIBLE);
                    /*显示我的答案*/
                    if (!stuAnswer.equals("")) {
                        holder.TvStuAnswer.setText(stuAnswer);
                        if (stuAnswer.equals(answer)) {
                            holder.TvStuAnswer.setTextColor(tvGreen);
                        } else {
                            holder.TvStuAnswer.setTextColor(tvRed);
                        }
                    } else {
                        holder.TvStuAnswer.setText(R.string.znbk_no_answered);
                        holder.TvStuAnswer.setTextColor(tvRed);
                    }
                    /*显示参考答案*/
                    holder.TvAnswer.setText(answer);
                    /*显示解析*/
                    if (!analysis.equals("")) {
                        holder.TvAnalysis.setText(analysis);
                    } else {
                        holder.TvAnalysis.setText(R.string.znbk_no_analysis);
                    }
                } else {
                    holder.LayoutCheckAnalysis.setVisibility(View.GONE);
                }
            }
        }
    }
    /*
    * 写入作答信息
    * */
    private void setStuAnswerInfor(String strStuAnswer,int recPaperID){
        if(ModelFrom== ZnbkPaperDef.FROM_TRAINING_DIFFICULT_PROBLEMS){
            mEntityNtxl.getTKQue().getChildList().get(OptionID).getSubChildList().get(0).
                    setSubChildStuAnswer(strStuAnswer);
        }else if(ModelFrom==ZnbkPaperDef.FROM_WRONG_TOPIC_TUTORING){
            mEntityCtfd.getRecQues().get(recPaperID).getTKQue().getChildList().get(OptionID).
                    getSubChildList().get(0).setSubChildStuAnswer(strStuAnswer);
        }else if(ModelFrom==ZnbkPaperDef.FROM_SYSTEM_REVIEW){
            mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().
                    get(OptionID).getSubChildList().get(0).setSubChildStuAnswer(strStuAnswer);
        }else if(ModelFrom==ZnbkPaperDef.FROM_WEEK_ASCENSION){
            mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().
                    get(OptionID).getSubChildList().get(0).setSubChildStuAnswer(strStuAnswer);
        }
    }
}